C/C++ GPIO Development¶
This document describes the recommended C/C++ GPIO workflow on Quectel Pi M1/L1. The checked development board image supports libgpiod v1.6.3. lgpio libraries and lgpio.h were not detected, so libgpiod is the default path.
Prepare Environment¶
sudo apt update
sudo apt install -y build-essential gpiod libgpiod-dev
gpiodetect --version
gpiodetect
Item |
Description |
|---|---|
Recommended library |
libgpiod |
Link flag |
|
Main controller |
Currently verified as |
Read Example¶
#include <gpiod.h>
#include <stdio.h>
int main(void)
{
struct gpiod_chip *chip = gpiod_chip_open_by_name("gpiochip0");
struct gpiod_line *line = gpiod_chip_get_line(chip, 36);
gpiod_line_request_input(line, "m1-gpio-input");
printf("value=%d\n", gpiod_line_get_value(line));
gpiod_line_release(line);
gpiod_chip_close(chip);
return 0;
}
gcc -Wall -o gpio_input gpio_input.c -lgpiod
sudo ./gpio_input
Output Example¶
#include <gpiod.h>
#include <unistd.h>
int main(void)
{
struct gpiod_chip *chip = gpiod_chip_open_by_name("gpiochip0");
struct gpiod_line *line = gpiod_chip_get_line(chip, 36);
gpiod_line_request_output(line, "m1-gpio-output", 1);
sleep(1);
gpiod_line_set_value(line, 0);
gpiod_line_release(line);
gpiod_chip_close(chip);
return 0;
}
gcc -Wall -o gpio_output gpio_output.c -lgpiod
sudo ./gpio_output
Notes¶
Confirm the real line offset from the M1 pin definition before wiring.
If runtime access fails, check line usage with
gpioinfo /dev/gpiochip0.If
gpiod.his missing, installlibgpiod-dev.